﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_AllGoodsList : System.Web.UI.Page, IAccess
{
    protected void Page_Load(object sender, EventArgs e)
    {

        CurrentAccount.CheckSessionTimeOut(this);
        if (!IsPostBack)
        {
            Bind();
        }
    }
    protected void pager1_PageChanging(object sender, HZ.Web.PageChaningEventArgs e)
    {
        Bind();
    }

    private void Bind()
    {
        int totalrecord;

        string append;
        if (!string.IsNullOrEmpty(txtCompanyName_TB.Text))
        {
            append = string.Format("CompanyId_Tb IN (SELECT c.CompanyId FROM dbo.TB_Company AS c WHERE c.CompanyName LIKE '%{0}%')", txtCompanyName_TB.Text.Trim());
        }
        else
        {
            append = null;
        }

        var bidprice = BLL_Factory.IBLL_Company.GetBidPrice(new HZ.BidSystem.Model.QBidPrice() { SortFields = "ProductID", ProductName = txtProductName.Text.Trim(), Model = txtMedicineModel.Text.Trim(), Outlookc = txtOutlookc.Text.Trim(), CompanyName_Sc = txtCompanyName_sc.Text.Trim(), Append = append }, pager1.CurrentPage, pager1.PageSize, out totalrecord);

        pager1.RecordCount = totalrecord;

        gv1.DataSource = bidprice;
        gv1.DataBind();
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        pager1.CurrentPage = 1;
        Bind();
    }
    protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gv1.EditIndex = e.NewEditIndex;
        Bind();
    }
    protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Reset the edit index.
        gv1.EditIndex = -1;

        GridViewRow row = gv1.Rows[e.RowIndex];
        string Company_Goods = new HZ.Common.ConvertHelper(row.Cells[0].Text).ToString();

        var newlimitprice = new HZ.Common.ConvertHelper((row.FindControl("txtLitmit") as TextBox).Text).ToDouble.Value;
        //Bind data to the GridView control.
        BLL_Factory.IBLL_Manage.UpdateLimitPrice(Company_Goods, newlimitprice);
        Bind();


    }
    protected void gv1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        //Reset the edit index.
        gv1.EditIndex = -1;
        //Bind data to the GridView control.
        Bind();

    }

    protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    var lbl = e.Row.FindControl("lblCompanyId_Tb") as Label;
        //    lbl.Text = HZ.BidSystem.BLL.BLL_Cache.CompanyCache[int.Parse(lbl.Text)].CompanyName;

        //}
    }
    #region IAccess Members

    IList<EnumAccess> IAccess.AccessList
    {
        get
        {
            var list = new List<EnumAccess>();
            list.Add(EnumAccess.Manage);
            return list;
        }

    }

    #endregion
    protected void btnExport_Click(object sender, EventArgs e)
    {
        HZ.Web.WebUtil.ExportToExcel(HZ.Data.DbHelperFactory.Create().ExecuteTable(@"SELECT  ProductCode 招标单元,Company_Goods 流水号, ProductName 通用名, Model 剂型, Outlookc 规格,PackUnit 包装单位, MaterialUnit 最小制剂单位, PackFactor 转换系数,PackMaterials 包装,Weights 装重量,QualityLevelName 竞价组,
        CompanyName_SC 生产企业, CompanyName_Tb 投标企业 ,LimitPrice 限价

FROM    dbo.View_BidPrice where ProductName like '%" + txtProductName.Text.Trim()  + "%' and Model like '%" + txtMedicineModel.Text.Trim() + "%' and Outlookc like '%"+txtOutlookc.Text.Trim() +"%' and CompanyName_SC like '%"+txtCompanyName_sc.Text.Trim()+"%' and CompanyName_Tb like '%"+txtCompanyName_TB.Text.Trim()+"%'  ORDER BY ProductCode"), "export.xls");
    }

    ////,        LimitPrice 限价
}
